module PrayersHelper

	def display_created_time(prayer)
		if prayer.created_at
			prayer.created_at.localtime.to_formatted_s(:sp_default)
		end
	end

	def display_prayer_bottoms(prayer)
			bullet = "&lowast;"
			if logged_in?
				if prayer.has_collaborated_with?(@signed_user)
					action = link_to_function "I Got Answered", "RenderLayer(event, 'answers?prayer_id=#{prayer.id}')"
				else
					action = link_to_remote "I'll pray with you", :url => be_collaborator_prayer_path(prayer)
				end
			else
				action = link_to "Sign In First", signin_path, :class => "sign_in"
			end

			collaborators = "&nbsp;COLLABORATORS: <span class='number'>#{number_with_delimiter(prayer.collaborators.size)}&nbsp;</span>"

			if logged_in? && prayer.has_collaborated_with?(@signed_user)
				answers = link_to_function "&nbsp;ANSWERS: <span class='number'>#{number_with_delimiter(prayer.answers.size)}&nbsp;</span>", "RenderLayer(event, 'answers?prayer_id=#{prayer.id}')"
			else
				answers = "&nbsp;ANSWERS: <span class='number'>#{number_with_delimiter(prayer.answers.size)}&nbsp;</span>"
			end

		"<p><span class='action_message'>#{collaborators}</span> <span class='action_message'>#{answers}</span></p>" +
		"<p><span class='action_bullet'>#{bullet}</span> #{action}</p>"
	end

	def display_edit_button(prayer)
		if logged_in? && prayer.owned_by?(@signed_user)
			"<span class='edit_button'>&rArr;#{link_to_function "Edit", "RenderLayer(event, 'edit_prayer?prayer_id=#{prayer.id}')" }</span>"
		end
	end

	def display_destroy_button(prayer)
		if prayer.has_collaborated_with?(@signed_user)
			if prayer.owned_by?(@signed_user)
				path = prayer_path(prayer)
				confirm_message = "Destroy?"
			else
				path = stop_collaborating_prayer_path(prayer)
				confirm_message = "Stop Collaborating?"
			end

			link_to_remote :x, :url => path, :method => :delete, :confirm => confirm_message 
		end
	end

end
